<?php

declare (strict_types=1);

namespace App\Model\GuildManage;

use App\Model\Guild\GuildBase;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Model;

/**
 * @property int $id
 * @property int $user_id
 * @property string $have_access_balance
 * @property string $audit_access_balance
 * @property int $guild_manage_id
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 */
class GuildBalance extends GuildBase
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'guild_balance';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'user_id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    /**
     * 根据用户id获取余额
     * @param $userId
     * @return Builder|Model|object|null
     */
    public function getBalanceInfoByUserId($userId)
    {
        return $this->where('user_id', $userId)->first();
    }

    /**
     * 根据工会id获取余额
     * @param $guildId
     * @return Builder|Model|object|null
     */
    public function getBalanceInfoByGuildId($guildId)
    {
        return $this->where('guild_manage_id', $guildId)->first();
    }
}